package com.gk.company.view.top
{
	import com.gk.company.control.event.UpdateUserInfoEvent;
	import com.gk.company.interfaces.IUserInfoVo;
	import com.gk.company.view.event.GoFriendCompanyEvent;
	import com.gk.company.view.event.GoMyCompanyEvent;
	
	import flash.events.Event;
	
	import flashx.textLayout.events.UpdateCompleteEvent;
	
	import org.robotlegs.mvcs.Mediator;
	
	public class TopInfoMediator extends Mediator
	{
		[Inject]
		public var topInfoView:TopInfoView;
		
		public function TopInfoMediator()
		{
			super();
		}
		
		override public function onRegister():void
		{
			eventMap.mapListener(eventDispatcher,UpdateUserInfoEvent.UPDATE_PIC_NAME,updateViewPicName,UpdateUserInfoEvent)
			eventMap.mapListener(eventDispatcher,UpdateUserInfoEvent.UPDATE_USER_KB,updateViewKB,UpdateUserInfoEvent)
			eventMap.mapListener(eventDispatcher,UpdateUserInfoEvent.UPDATE_USER_MB,updateViewMB,UpdateUserInfoEvent)
			eventMap.mapListener(eventDispatcher,UpdateUserInfoEvent.UPDATE_USER_POPULAR,updateViewP,UpdateUserInfoEvent)
			
			eventMap.mapListener(eventDispatcher,GoFriendCompanyEvent.GO_FRIEND_COMPANY,updateAllData,GoFriendCompanyEvent)
			eventMap.mapListener(eventDispatcher,GoMyCompanyEvent.GO_MY_COMPANY,updateAllData,GoMyCompanyEvent)
		
		
		}
		
		private function updateAllData(e:Event):void
		{
			if(e is GoFriendCompanyEvent){
				topInfoView.updateAllInfo(GoFriendCompanyEvent(e).userInfoVo);
			}else if(e is GoMyCompanyEvent){
				topInfoView.updateAllInfo(GoMyCompanyEvent(e).userInfoVo);
			}
			topInfoView.changeUpgrade((e is GoMyCompanyEvent));
		}
		
		private function updateViewKB(e:UpdateUserInfoEvent):void
		{
			topInfoView.updateKB(e.userInfoVo.kbNum);
		}
		private function updateViewMB(e:UpdateUserInfoEvent):void
		{
			topInfoView.updateMB(e.userInfoVo.mbNum);
		}
		private function updateViewP(e:UpdateUserInfoEvent):void
		{
			topInfoView.updatePopular(e.userInfoVo.popularNum);
		}
		
		private function updateViewPicName(e:UpdateUserInfoEvent):void
		{
			topInfoView.updateInfo(e.userInfoVo.user_pic,e.userInfoVo.user_name);
		}
		
	}
}